package com.app.brilliant.util;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
//       testSelenium();
        long number = 2315646541231321L;
        long center = (long)Math.sqrt(number);
        for (long i = 2; i < center; i++) {
            if(number % i == 0){
                System.out.println(i);
                break;
            }
        }
        System.out.println(BigDecimal.valueOf(4812116521L).multiply(BigDecimal.valueOf(4812116521L)));
    }

    private static void testJsoup() throws IOException {
        String url = "https://zhuanlan.zhihu.com/p/13156321185";
        Document doc = Jsoup.connect(url).
                userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
                .header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
                .header("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2")
                .header("Accept-Encoding", "gzip, deflate, br")
                .header("Connection", "keep-alive")
                .header("Referer", "https://www.zhihu.com/")
                .timeout(10000)
                .get();
        System.out.println(doc.text());
    }

    private static void testSelenium() throws Exception {
       System.setProperty("webdriver.chrome.driver","D:\\googleDriver\\chromedriver-win64\\chromedriver.exe");
       ChromeOptions chromeOptions = new ChromeOptions();
//       chromeOptions.addArguments("--headless");
       chromeOptions.addArguments("--disable-blink-features=AutomationControlled");
       chromeOptions.addArguments("--disable-gpu");
       chromeOptions.addArguments("--disable-features=SameSiteByDefaultCookies");
       chromeOptions.addArguments("--disable-extensions");
       chromeOptions.addArguments("--disable-dev-shm-usage");
       chromeOptions.addArguments("--incognito");
       String user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";
       chromeOptions.addArguments("--user-agent=" + user_agent);
       WebDriver driver = new ChromeDriver(chromeOptions);
       List<Cookie> cookies = addCookie();
       for (Cookie cookie : cookies) {
           driver.manage().addCookie(cookie);
       }
       driver.manage().timeouts().implicitlyWait(10, java.util.concurrent.TimeUnit.SECONDS);
       driver.get("https://zhuanlan.zhihu.com/p/13156321185");
       System.out.println(driver.getPageSource());
       //       driver.close();
    }

    private static List<Cookie> addCookie(){
        String cookieInfo = "__snaker__id=0QNlIjlItgC5zSL1; SESSIONID=IIo5I98oqmqlz3tHprcTreAVl43s3WxXoW7iIREy3hc; JOID=Vl8cCkqa6bWOo3HXUcRJa-e7u6hGusSWpYVR-nK8yZitiFf3fFexJOulfNlZxP_v9gKFHsV7dohuOupyYnd9CT0=; osd=VVsUA0iZ7b2HoXLTWc1LaOOzsqpFvsyfp4ZV8nu-ypylgVX0eF-4JuihdNBbx_vn_wCGGs1ydItqMuNwYXN1AD8=; _xsrf=cruBN9NxdPkHbVlPqf6U5TjeBQ8O2AVi; _zap=cae93755-de44-4d0b-b6b0-8e2d06b49a90; d_c0=7oITI9WEYRqPTrc_Y2Nnlnu2_fTyTq4uwt0=|1746000979; _ga=GA1.2.1005242127.1753762951; _ga_MKN1TB7ZML=GS2.2.s1753762956$o1$g0$t1753762956$j60$l0$h0; tst=r; gdxidpyhxdE=vmtCkrpQluyXhfN1Vc8Q0XKws5%2BqNNS9wPEm3xlf1HhDLhrx8uB0JdK1PDw%2BdspTWdSdhYWNPC0JLRYxC8TLC1TS9OHc7fuJm17VipvuInCgEAIY%2FLbZEtASbD3HXbcOX3o2nPn31e%2Fg%2BOIJ1PjilwxcMIuZHWU3OtAnjb7%5CLPgw97tx%3A1753968810099; captcha_session_v2=2|1:0|10:1753967923|18:captcha_session_v2|88:YSs2ZE9zaTA0QjNLSmI2b21lN0xQdFdZR3lHaUxDbllQZlR3WG8rTHErUTZVUDlNV0JDcEdRUmZqYUxyQmhMUQ==|d1555d563534894c1ec99a17c6f0274b9a1967410f7c1017d0a18797442c2c3c; captcha_ticket_v2=2|1:0|10:1753967938|17:captcha_ticket_v2|728:eyJ2YWxpZGF0ZSI6IkNOMzFfMURpUWxGd1cxeEhWQ1ZDazZyeipiVXduRFNpMDZmbjlwcEs2VlBRTkR1UFNET2E5T3B2S3VjdmhQOHMwV21kUGJCLksyNFZoMWF3c1Ria3NUWkpocWo1X0pQYlpHR3FlZV9tRW9WKlFqS2lsYUJsSHMxZ1FrNEQxYkI1ZElGZ29NS2xxV2FwVm5IUWdOWm9ORkUxM204NW9NNVpoeDlSRUJPb0VmKjRYTURKdTJqZkZ5OWhtWGdMenJmSGdLNnJjczhuUEthdXM5ekE1WTZGaCoydlNwWUVEdmlhaHBBeWxfcHRGc1Q2aXp0LlVaRXphVSpycDZhMmpwTGlNdVJ3MjhtV2QzVTFyKnFBUW11SUxJZnVPNmRJODMuSGFwSmhxaklZbTVfLmdmRUJjaDRQVGZtM1ByclVLVVd3TC5wTzgzbWx5bTJQKll4MldVWlRSd2RoQmlDQ19HX2JKOFA4eTJtYUZvUUVBUXpHS3ZqTjR2QXlZR3RsOG1SRGxqWlZIMUFsVk1fc1VZbk91VHFGMjFDbVhVVnhlUU1meVZOZUhHUXhaMEtOdjl6MC5TLmlIdHV6QUwzeUh1andpRHNUbjhBNnAza0t1MTV3U2pGbHA0QjZ2OVpIdVRkaF8yaFZ5KnVLa0xfMkpjR0lXUTlSaWRucSouYVFXcW5ZZW0qWWZRMndoX1k3N192X2lfMSJ9|488d45787d06abdfb150b604d2020d59081ed3c59d7935f4d86ec065df5f4660; z_c0=2|1:0|10:1753967938|4:z_c0|92:Mi4xS3dWM0F3QUFBQUR1Z2hNajFZUmhHaVlBQUFCZ0FsVk5RcnQ0YVFCWWRNMzkyTzRseXF2RjgzT1hjYmt0RkJlWkFB|41d42e7f5399c9571cd51009ded75ce08d55083c2cf19ee1f74270c30035b824; Hm_lvt_98beee57fd2ef70ccdd5ca52b9740c49=1753865404,1754057429,1754057731,1754376017; __zse_ck=004_njbWaeuR5tVrGfkyp0Dba6VZRd/DcCHz8dtWU37clEMWo=3YK6OS32XSv54eimE6SCOh1oY9/hIIK71VIhSGnYgxii1wP6fHPA4YlZPJM/J/VUHRfXrYo7TFsub/QyLj-TyC/lt0lsSw+TO1fb5Ipji9UVQ9ALZh/PIQmMlj8uCw+iMFznhccuoF/PeAVMXWq4HqA6EdWBwUlaiBEOA8SOwkBeZgBhAfpKbPX3iW18XpBWbyWHu4Eur+XlcF8ETZX; BEC=b7b0f394f3fd074c6bdd2ebbdd598b4e";
        List<Cookie> cookieList = getCookies(cookieInfo);
        return cookieList;
    }

    private static List<Cookie> getCookies(String cookieInfo) {
        String[] cookies = cookieInfo.replaceAll("\\s+","").split(";");
        List<Cookie> cookieList = new ArrayList<>();
        for (String cookie : cookies) {
           String[] cookieParts = cookie.split("=");
           if (cookieParts.length >= 2) {
              StringBuilder value = new StringBuilder();
              for(int i = 1; i < cookieParts.length; i++){
                  value.append(cookieParts[i]);
              }
              Cookie localCookie = new Cookie(cookieParts[0], value.toString(),".zhihu.com","/",null,true,false);
              cookieList.add(localCookie);
           }
        }
        return cookieList;
    }
}
